package com.das.mechanic_base.widget;

import com.das.mechanic_base.bean.siveprocess.SiveProBean;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.greenrobot.greendao.converter.PropertyConverter;

import java.util.List;

/**
 * 作者：zhanglei on 2019/11/16 10:38
 * <p>
 * 邮箱：916256628@qq.com
 */
public class ProcessConverter implements PropertyConverter<List<SiveProBean>, String> {
    @Override
    public List<SiveProBean> convertToEntityProperty(String databaseValue) {
        if (databaseValue == null) {
            return null;
        } else {
            // 先得获得这个，然后再typeToken.getType()，否则会异常
            TypeToken<List<SiveProBean>> typeToken = new TypeToken<List<SiveProBean>>() {
            };
            return new Gson().fromJson(databaseValue, typeToken.getType());
        }
    }

    @Override
    public String convertToDatabaseValue(List<SiveProBean> entityProperty) {
        if (entityProperty == null || entityProperty.size() == 0) {
            return null;
        } else {
            String sb = new Gson().toJson(entityProperty);
            return sb;

        }
    }
}
